#!/bin/bash

touch cu.log
cp /etc/apt/sources.list /etc/apt/sources.list.old

#echo "deb http://debian.ustc.edu.cn/ubuntu/ raring main multiverse restricted universe
#deb http://debian.ustc.edu.cn/ubuntu/ raring-backports main multiverse restricted universe
#deb http://debian.ustc.edu.cn/ubuntu/ raring-proposed main multiverse restricted universe
#deb http://debian.ustc.edu.cn/ubuntu/ raring-security main multiverse restricted universe
#deb http://debian.ustc.edu.cn/ubuntu/ raring-updates main multiverse restricted universe
#deb-src http://debian.ustc.edu.cn/ubuntu/ raring main multiverse restricted universe
#deb-src http://debian.ustc.edu.cn/ubuntu/ raring-backports main multiverse restricted universe
#deb-src http://debian.ustc.edu.cn/ubuntu/ raring-proposed main multiverse restricted universe
#deb-src http://debian.ustc.edu.cn/ubuntu/ raring-security main multiverse restricted universe
#deb-src http://debian.ustc.edu.cn/ubuntu/ raring-updates main multiverse restricted universe" > /etc/apt/sources.list

apt-get update || echo "error: apt-get update failed." >> cu.log
apt-get upgrade

# vim 
apt-get install -y vim-common=2:7.3.547-6ubuntu5 && \
apt-get install -y vim || echo "error: failed to install vim" >> cu.log

# gcc
apt-get install -y gcc || echo "error: failed to install gcc" >> cu.log

# g++
apt-get install -y libc6=2.17-0ubuntu5.1 && \
apt-get install -y libc6 && \
apt-get install -y libstdc++6-4.7-dev &&
apt-get install -y g++ || echo "error: failed to install g++" >> cu.log


# Bradcom 802.11 Linux STA 无线网卡驱动
apt-get install -y libdpkg-perl=1.16.10ubuntu1 build-essential libalgorithm-merge-perl && \
apt-get install -y dpkg-dev && \
apt-get install -y debhelper && \
apt-get install -y bcmwl-kernel-source && \
apt-get install -y broadcom-sta-common && \
apt-get install -y broadcom-sta-source && \
# Broad 43xx 固件提取工具
apt-get install -y b43-fwcutter && \
apt-get install -y firmware-b43-installer && \
# 激活无线网卡
modprobe -r b43 ssb && \
modprobe b43  || echo "error: 无线网卡安装失败." >> cu.log

# 调教Nvidia驱动
add-apt-repository ppa:bumblebee/stable && \
apt-get update && \
apt-get install -y bumblebee bumblebee-nvidia  || echo "error: 安装Nvidia drivers failed." >> cu.log
# "Need reboot
# "The Follow to See how Nvidia Run
# sudo optirun nvidia-settings -c :8
# "To run program using Nvidia
# sudo optirun + program_name

# 卸载不需要的程序
# 即时通信
#apt-get -y purge empathy && \
#apt-get -y purge nautilus-sendto-empathy && \
#apt-get -y purge empathy-common && \
# 邮件
#apt-get -y purge thunderbird* && \
# apt-get autoremove indicator-messages && \
# apt-get -y purge gwibber*
# Ubuntu One
#apt-get -y purge ubuntuone* && \
# apt-get -y purge update-* && \
# 打印
#apt-get -y purge hplip* && \
#apt-get -y purge printer-driver* && \
# 问题报告
#apt-get -y purge apport* && \
# 扫描
#apt-get -y purge simple-scan && \
# 崩溃报告
#apt-get -y purge whoopsie && \
#apt-get -y purge samba-common* && \  #samba共享

# 办公套件
# apt-get -y purge libreoffice* && \

# 安装需要的程序
# apt-get install -y python && \
# apt-get install -y apcalc && \
apt-get install -y smplayer || echo "error: install smplayer failed." >> cu.log
apt-get install -y git || echo "error: failed to install git" >> cu.log
apt-get install -y gitk || echo "error: failed to install gitk" >> cu.log
# ssh
apt-get install -y openssh-client=1:6.1p1-4 && \
apt-get install -y openssh-server && \
apt-get install -y ssh || echo "error: failed to install ssh" >> cu.log

apt-get install -y filezilla || echo "error: failed to install filezilla" >> cu.log
apt-get install -y subversion || echo "error: failed to install subversion." >> cu.log
apt-get install -y virtualbox || echo "error: failed to install virtualbox." >> cu.log
apt-get install -y convmv || echo "error: failed to install convmv" >> cu.log
apt-get install -y tree || echo "error: failed to install tree" >> cu.log

# python-setuptools --> easy_install
apt-get install -y python-pkg-resources=0.6.34-0ubuntu1 && \
apt-get install -y python-setuptools || echo "error: failed to install python-setuptools" >> cu.log
# 利用easy_install 安装virtualenv
# easy_install virtualenv
apt-get install -y python-virtualenv || echo "error: failed to install python-virtualenv" >> cu.log

# nautilus 
apt-get install -y libgtk-3-common=3.6.4-0ubuntu8 && \
apt-get install -y nautilus || echo "error: failed to install nautilus" >> cu.log

# 安装Brackets.io , html, js
# http://brackets.io
wget -O Brackets.deb https://github.com/adobe/brackets/releases/download/sprint-38/Brackets.Sprint.38.64-bit.deb && \
			 dpkg -i Brackets.deb || echo "error: failed to install brackets.deb" >> cu.log

# 安装flash插件
apt-get install -y flashplugin-installer || echo "error: failed to install flashplugin" >> cu.log

# 安装 chrome
wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb && \
apt-get install -y libxss1 && \
dpkg -i google-chrome-stable_current_amd64.deb && \
rm -rf google-chrome-stable_current_amd64.deb || \
# apt-get install -y google-chrome-stable && \
# apt-get -f install && \
# dpkg -i google-chrome-stable_current_amd64.deb && \
echo "error: failed to install google-chrome" >> cu.log

# njit-client
# libpcap-dev
apt-get install -y --force-yes libpcap0.8=1.3.0-1 && \
apt-get install -y libpcap0.8-dev && \
apt-get install -y libpcap-dev && \
# libssl-dev
apt-get install -y --force-yes libssl1.0.0=1.0.1c-4ubuntu8.2 && \
apt-get install -y --force-yes zlib1g=1:1.2.7.dfsg-13ubuntu2 && \
apt-get intsall -y libssl-dev && \
#
apt-get install -y pkg-config && \
apt-get install -y automake && \
git clone https://github.com/liuqun/njit8021xclient.git && \
cd njit8021xclient/ && \
./help && \
make && make install && \
cd .. && \
rm -rf njit8021xclient* || echo "error: failed to install njit-client." >> cu.log

# 好用的音乐播放器
wget https://iceplayer.googlecode.com/files/iceplayer-amd64-4.0.5-20110520.deb && \
dpkg -i iceplayer*
# 解决依赖
apt-get -f -y install && dpkg -i iceplayer* && \
rm -rf iceplayer* || echo "error: failed to install iceplayer." >> cu.log
# 针对ubuntu13.04 kernel 3.8.x 缺少libnotify.so.1
apt-get install -y python-notify
ln -s /usr/lib/x86_64-linux-gnu/libnotify.so.4 /usr/lib/x86_64-linux-gnu/libnotify.so.1

# 安装KDE桌面
# apt-get install kubuntu-desktop || echo "error: failed to install kubuntu-desktop"

echo "Reboot 10 seconds later..."
sleep 10

#reboot 


exit 0
